#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ == taoyulong2018@gmail.com
# __time__ == 2023/8/17 10:13
# ===========================================
#       题目名称： 4. 寻找两个正序数组的中位数
#       题目地址： https://leetcode.cn/problems/median-of-two-sorted-arrays/
#       题目描述： https://note.youdao.com/s/RRXNSXjR
# ===========================================

import numpy as np
import math

class Solution:
    """
        算法的时间复杂度应该为 O(log (m+n))
        实现思路：
            O(log (m+n)) 不是很懂
    """

    def findMedianSortedArrays(self, nums1, nums2):
        result= 0
        stack = nums1 + nums2
        stack.sort()
        if len(stack) % 2 == 0:
            point = int(len(stack) / 2) - 1
            result = (stack[point] + stack[point + 1]) / 2.0
        else:
            result = stack[int(len(stack) / 2)]
        return result

    def findMedianSortedArrays2(self, nums1, nums2):
        return np.median(nums1 + nums2)


if __name__ == '__main__':
    s = Solution()
    print("2.00000 => ", s.findMedianSortedArrays(nums1=[1, 3], nums2=[2]))
    print("2.50000 => ", s.findMedianSortedArrays(nums1=[1, 2], nums2=[3, 4]))
